package com.devmindset.legoframework.usage.client.component;

import com.devmindset.legoframework.client.mvc.LegoComponent;
import com.devmindset.legoframework.client.mvc.LegoModel;
import com.devmindset.legoframework.client.mvc.metadata.ComponentStory;
import com.devmindset.legoframework.client.mvc.metadata.Stories;
import com.devmindset.legoframework.client.screen.ApplicationScreenManager;
import com.devmindset.legoframework.usage.client.event.Events;
import com.devmindset.legoframework.usage.client.screen.MainScreen;
import com.devmindset.legoframework.usage.client.text.UsageTexts;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Cursor;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

public class OrganizerHeaderComponent extends LegoComponent {

	/** {@inheritDoc} */
	@Override
	public Canvas construct(LegoModel model) {
		HLayout layout = new HLayout();
		layout.setWidth100();
		layout.setHeight100();
		layout.setAlign(Alignment.CENTER);
		layout.setMembersMargin(4);
		Label text = new Label("<b>[ " + UsageTexts.get().returnBackToMainScreen() + " ]</b>");
		text.setWrap(false);
		text.setHeight(12);
		text.setWidth(30);
		text.setCursor(Cursor.HAND);
		text.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				ApplicationScreenManager.activate(MainScreen.class);
			}
		});
		
		layout.addMember(text);		
		return layout;
	}
	
	/** {@inheritDoc} */
	@Override
	public void calculate(LegoModel model) {
		//one-time construction component; nothing to (re)calculate.
	}
	
	/** {@inheritDoc} */
	public ComponentStory myStory() {
		return Stories.component()
			.constructedBy(Events.RENDER_ORGANIZER_HEADER_COMPONENT)
			.knownAs("Organizer Header Component");
	}
	
}